package pdm.traj.frontend;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import pdm.traj.entity.TrackPoint2;
import pdm.traj.entity.TrajQuery;
import pdm.traj.entity.TrajQueryResult;
import pdm.traj.service.TrajDataService;

public class TrajMonitorServlet extends HttpServlet {
	TrajDataService trajDataService = null;
	
	@Override
	public void init(ServletConfig sc) throws ServletException {
		super.init(sc);
//		service = TrajDataServiceFactory.getInstance().getService(0);
		ApplicationContext context = new ClassPathXmlApplicationContext("spring-webcontext.xml");
		trajDataService = (TrajDataService) context.getBean("trajDataService", TrajDataService.class);

	}
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
	throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		TrajQuery query = new TrajQuery();
		query.setOnlineUserSum(true);
//		TrajQueryResult result = trajDataService.query(query);
//		out.write("online user sum: " + result.getOnlineUserSum() + "</br>");
//		out.write("update count: " + result.getUpdateCount() + "</br>");
//		for (TrackPoint2 tp : result.getTpl()) {
//			out.write(tp + "<br/>");
//		}
		out.close();
	
	}

}
